package com.liangzong.betspider.service;

import com.liangzong.betspider.entity.TeamPoint;
import com.liangzong.betspider.entity.TeamScore;
import com.liangzong.betspider.mapper.TeamScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Assert;

import java.util.List;


@Service
public class TeamScoreService {

    @Autowired
    TeamScoreMapper teamScoreMapper;

    @Transactional(rollbackFor = Throwable.class)
    public boolean addOrUpdate(String teamId, TeamScore homeTeamScore, TeamScore awayTeamScore) {
        Example o = new Example(TeamScore.class);
        o.and().andEqualTo("teamId", teamId);
        //清理数据
        teamScoreMapper.deleteByExample(o);
        //保存
        Assert.isTrue(teamScoreMapper.insertSelective(homeTeamScore) > 0, "保存主队比分异常");
        Assert.isTrue(teamScoreMapper.insertSelective(awayTeamScore) > 0, "保存客队比分异常");
        return true;
    }

    public List<TeamScore> getByTeamId(String teamId){
        Example o = new Example(TeamScore.class);
        o.and().andEqualTo("teamId", teamId);
        return teamScoreMapper.selectByExample(o);
    }
}
